unit SaidaRecordFr;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls, ComCtrls, DBCtrls, ActnList, Buttons, DBGrids, ExtCtrls, EditBtn,
  MainTransactionRecordFr, DataRecord;

type

  { TSaidaRecordFrame }

  TSaidaRecordFrame = class(TMainTransactionRecordFrame)
    AlterarPrecoAction: TAction;
    BuscarProduto: TBitBtn;
    codigoEdit: TEdit;
    DBMemo1: TDBMemo;
    descricaoEdit: TEdit;
    UnEdit: TEdit;
    IDUsuarioDBEdit: TDBEdit;
    Label2: TLabel;
    Label23: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Panel3: TPanel;
    quantidadeEdit: TEdit;
    SalvarPrecoAction: TAction;
    CancelarPrecoAction: TAction;
    AprazoTabSheet: TTabSheet;
    AvistaTabSheet: TTabSheet;
    CartaoTabSheet: TTabSheet;
    DBGrid3: TDBGrid;
    DBGrid4: TDBGrid;
    DBGroupBox3: TDBGroupBox;
    DBGroupBox5: TDBGroupBox;
    DBGroupBox6: TDBGroupBox;
    DescontoCartaoDBEdit: TDBEdit;
    DescontoChequeDBEdit: TDBEdit;
    DetailDBGrid: TDBGrid;
    DetailGroupBox: TGroupBox;
    diaVencimentoCheque2: TDateEdit;
    GerarCheques1: TButton;
    GerarDuplicatasPrazo1: TButton;
    GroupBox2: TGroupBox;
    id_saida: TDBEdit;
    Label1: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label8: TLabel;
    MasterGroupBox: TGroupBox;
    MasterTabSheet: TTabSheet;
    data: TDBEdit;
    Pagamento1: TPageControl;
    Painel3: TPanel;
    PainelTroco: TPanel;
    Panel11: TPanel;
    Panel12: TPanel;
    Panel13: TPanel;
    Panel16: TPanel;
    Panel17: TPanel;
    Panel2: TPanel;
    Panel6: TPanel;
    Panel7: TPanel;
    RecordPageControl: TPageControl;
    RemoverItensProdutos: TSpeedButton;
    StatusCliente: TDBRadioGroup;
    TotalCartaoPainel: TPanel;
    TotalChequePainel: TPanel;
    TotalPainel: TDBText;
    TotalPrazoPainel: TPanel;
    TrocoPainel: TPanel;
    procedure BuscarProdutoClick(Sender: TObject);
    procedure descricaoEditChange(Sender: TObject);
    procedure InserirActionExecute(Sender: TObject);
    procedure codigoEditKeyPress(Sender: TObject; var Key: char);
    procedure ControlaBotoes(); override;
    procedure RemoverItensProdutosClick(Sender: TObject);
  //  procedure SetDataRecord(Data: TDataRecord); override;

   end;


implementation

uses Initializator, MainFr, SaidaDM, MainFm;

{ TSaidaRecordFrame }

procedure TSaidaRecordFrame.BuscarProdutoClick(Sender: TObject);
begin
  TheControl.ShowForeignFrame(TMainFrame(ProdutoSearchFrame));
end;

procedure TSaidaRecordFrame.descricaoEditChange(Sender: TObject);
begin
  codigoEdit.SetFocus();
end;

procedure TSaidaRecordFrame.InserirActionExecute(Sender: TObject);
begin
  SaidaData.LimpaItens();
  SaidaData.SaidaZQuery.Insert();
  SaidaData.SaidaZQuery.FieldByName('id_usuario').AsInteger:=MainForm.Usuario;
  SaidaData.SaidaZQuery.FieldByName('data').AsString:=SaidaData.BuscaData();
  ControlaBotoes();
end;

procedure TSaidaRecordFrame.codigoEditKeyPress(Sender: TObject; var Key: char);
var
  quant: real;
  valorTotal: real;
begin
  //! Verificar se é 13 para outros SO
  if (key = #13) then begin
    quant := StrToFloatDef(quantidadeEdit.Text, 0);
    SaidaData.SaidaAdicionaProduto(codigoEdit.Text, quant);
    quantidadeEdit.SetFocus();
  end;
end;

procedure TSaidaRecordFrame.ControlaBotoes();
var
  I: integer;
begin
    inherited ControlaBotoes;
    RecordPageControl.ActivePage := MasterTabSheet;
    DetailGroupBox.Enabled := AlterarAction.Enabled;
    BuscarProduto.Enabled := AlterarAction.Enabled;
  end;

procedure TSaidaRecordFrame.RemoverItensProdutosClick(Sender: TObject);
begin
  SaidaData.SaidaRemoveProduto();
end;

{procedure TSaidaRecordFrame.SetDataRecord(Data: TDataRecord);
begin
   codigoEdit.Text := Data.getValue('codigo_barra');
   descricaoEdit.Text := Data.getValue('desc_produto');
   UnidadeEdit.Text:= Data.getValue('sigla_unidade');
   inherited SetDataRecord(Data);
end;}


initialization
  {$I saidarecordfr.lrs}

end.
